﻿using AutoMapper;
using MediatR;
using MyMES.Domain.yjb;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.settingCommand;

namespace MyMES.Writer.API.Application.CommendHandlers.settingCommand
{
    public class DelTBCommandHandlers : IRequestHandler<DelTBCommand, APIResult<int>>
    {
        private readonly IBaseRepository<TransferOrder> accreop;
        private readonly IMapper mapper;

        public DelTBCommandHandlers(IBaseRepository<TransferOrder> accreop, IMapper mapper)
        {
            this.accreop = accreop;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(DelTBCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<int> result = new APIResult<int>();
                result.Code = APIEnum.删除成功;
                result.Msg = "删除成功";
                var process = mapper.Map<TransferOrder>(request);
                string sql = " update TransferOrder set  IsDelete=false where TransferOrderId=@TransferOrderId;";
                await accreop.Update(process, sql);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
